from wtforms import StringField, IntegerField
from app.validators.base import BaseForm as Form
from wtforms.validators import DataRequired, Length, NumberRange, Regexp


class SearchFrom(Form):
    """
    书籍搜索表单验证
    """
    q = StringField(
        validators=[
            DataRequired(),
            Length(min=1, max=30)
        ]
    )

    page = IntegerField(
        validators=[
            NumberRange(min=1, max=100),
        ],
        default=1
    )


class DriftFrom(Form):
    """
    书籍索要
    """
    recipient_name = StringField(
        validators=[
            DataRequired(),
            Length(min=2, max=20, message='收件人姓名长度必须在2到20个字符之间')
        ]
    )
    mobile = StringField(
        validators=[
            DataRequired(),
            Regexp('^1[0-9]{10}$', 0, '请输入正确的手机号')
        ]
    )
    message = StringField()
    address = StringField(
        validators=[
            DataRequired(),
            Length(min=10, max=70, message='地址还不到10个字吗？尽量写详细一些吧')
        ]
    )
